#!/usr/bin/env python
# -*- coding: utf-8 -*-


import sys
from datakeeper.models import DataSet, DatasetMold

ds_name = "ccmp"
mold_name = "CCMP"
ds_desc = u"大贤的CCMP海洋数据集"
desc = u"CCMP海洋数据集"


def run():
    try:
        mold = DatasetMold.objects.get(name=mold_name)
    except DatasetMold.DoesNotExist:
        print 'No such dataset mold: %s' % mold_name
        sys.exit(1)

    print "Creating dataset: %s" % ds_name
    ds = DataSet(
        name=ds_name,
        desc=ds_desc,
        creator="dxwind",
        version="1.0",
        free=True,
        priority=1200,
        mold=mold,
    )
    ds.info = {
        "name": "ccmp",
        "zh_name": u"CCMP海洋风场数据集",
        "years": ["1988", "1989",
                  "1990", "1991", "1992", "1993", "1994", "1995", "1996", "1997", "1998", "1999",
                  "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009",
                  "2010", "2011"],
        "begdt": "19880101 00",
        "enddt": "20120101 00",
        "desc": desc,
        "min_lon": 0.125,
        "max_lon": 359.875,
        "nx": 1440,
        "min_lat": -78.375,
        "max_lat": 78.375,
        "ny": 628,
        "lon_delta": 0.25,
        "lat_delta": 0.25,
        "limit": {
            "min_lon": 100.0,
            "max_lon": 129.875,
            "min_lat": 1.0,
            "max_lat": 44.875
        }
    }
    try:
        ds.save(update_fields=['desc', 'creator', 'version', 'mold', 'free', 'info_json'])
    except Exception:
        ds.save()


if __name__ == "__main__":
    run()